import { setToken } from '@/utils/auth'
import { login } from '@/api/test-user'

// 存储登录使用的token
const actions = {
  async login({commit},loginForm){
    let { data : { data: { token } } } = await login(loginForm)
    commit('SET_TOKEN',token)
  }
}

const mutations = {
  SET_TOKEN(state,token){
    // 拿到token数据
    state.token = token
    // 持久化到cookies
    setToken(token)
  }
}

const state = {
  token : null
}

export default {
  // 开启命名空间
  namespaced: true,
  state,
  mutations,
  actions,
}